using UnityEngine;
using System.Collections;

public class TriggerController : MonoBehaviour {

	public GameObject obj;
	public GameObject player;
	public int ammovalue = 1;
	private float hoverforce = 16.0f;
	private bool activated = true;
	private PlayerWControl script;
	
	delegate void DelayedMethod();
	
	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
	
	}
     
    IEnumerator WaitAndDo(float time, DelayedMethod method)
    {
	    yield return new WaitForSeconds(time);
	    method();
    }
	
	public void reactivateObj()
	{
		activated = true;
		obj.SetActive(true);
	}
	
	void OnTriggerEnter (Collider collider) {
        if (collider.gameObject.tag == "Player" && activated == true) {
			obj.SetActive(false);
			activated = false;
			script = player.GetComponent<PlayerWControl>();
			script.increaseAmmo(1);
			StartCoroutine(WaitAndDo(3, reactivateObj));
		}
    }
	
	void OnTriggerStay (Collider collider) {
        if (collider.gameObject.tag == "Gold") {
			collider.attachedRigidbody.AddForce (Vector3.up * hoverforce , ForceMode.Acceleration);
		}
    }
}
